package com.jiker;

import java.util.List;

/**
 * @author leo
 * @date 2021/6/16
 */
public class Coordinates {
    private Integer x;
    private Integer y;
    private Direction direction;

    public Coordinates(Integer x, Integer y, Direction direction) {
        this.x = x;
        this.y = y;
        this.direction = direction;
    }

    public Direction getDirection() {
        return direction;
    }

    public void setX(Integer x) {
        this.x = x;
    }

    public void setY(Integer y) {
        this.y = y;
    }

    public void setDirection(Direction direction) {
        this.direction = direction;
    }

    public Integer x() {
        return x;
    }

    public Integer y() {
        return y;
    }


    public void isBarrier(List<Barrier> barriers) {
        barriers.forEach(barrier -> {
            if (isBarrier(barrier)) {
                throw new RuntimeException("前方有障碍物!");
            }
        });
    }

    private boolean isBarrier(Barrier barrier) {
        return barrier.getX() == x && barrier.getY() == y;
    }

    @Override
    public String toString() {
        return "Coordinates{" +
                "x=" + x +
                ", y=" + y +
                ", direction=" + direction +
                '}';
    }
}
